<template>
  <div>
    <el-dialog title="无订单出行次数" ref="tableDialog" :visible="dialogVisible" width="70%" @close="close">
      <el-row>
        <el-col style="text-align: center;">
          <el-input
            v-model.trim="username"
            placeholder="输入单位名称"
            :style="'width:50%;margin:5px 0px;'"
            @keyup.enter.native="search"
          >
            <el-button slot="append" @click="search">搜索</el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col :sm="8">
          <div class="g-title">出行次数({{total}}个）</div>
        </el-col>
      </el-row>

      <el-table
        ref="multipleTable"
        :data="listData"
        tooltip-effect="dark"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="companyName" label="车牌号" show-overflow-tooltip align="center"></el-table-column>
        <el-table-column label="起始时间" align="center">2020/08/08 11:11</el-table-column>
        <el-table-column label="起始地点" align="center">xx小区</el-table-column>
        <el-table-column label="结束时间" width="120" align="center">2020/08/08 21:11</el-table-column>
        <el-table-column label="结束地点" width="120" align="center">xx小区</el-table-column>
      </el-table>
      <el-row style="padding: 32px 16px;">
        <el-col>
          <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :page-size="pageSize"
            :total="total"
            :current-page="pageNo"
            @current-change="fetchData"
            @size-change="pageSizeChange"
          ></el-pagination>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import { applyListjson } from "@/api/usecar";
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data: function() {
    return {
      username: "",
      total: 0,
      pageNo: 1,
      pageSize: 10,
      listData: [], //全部数据
      listDataSelected: [], //选中数据
      formData: null,
      userCarApplyVisible: false, //申请用车组件可见
      history: [] //历史流程
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    close() {
      this.$emit("update:dialogVisible", false);
    },
    showDetail(data) {
      this.dialogVisible = true;
    },
    //搜索
    search() {
      this.pageNo = 1;
      this.fetchData();
    },
    pageSizeChange(newSize) {
      this.pageSize = newSize;
      this.pageNo = 1;
      this.fetchData();
    },
    async fetchData(pageNo) {
      if (pageNo) {
        this.pageNo = pageNo;
      }
      let params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        username: this.username
      };
      let data = await applyListjson(params);
      this.listData = data.data;
      this.total = data.total;
      this.listDataSelected.splice(0);
    },
    //表格多选
    handleSelectionChange(val) {
      this.listDataSelected.splice(0);
      val.forEach(function(e) {
        app.listDataSelected.push(e);
      });
      console.log(this.listDataSelected);
    }
  }
};
</script>